'use strict'

let nunjucks = require('nunjucks');


function createEnv(path,opts){
    path = path || 'view';
    opts = opts || {};
    let nunjucksConfig = {
        IstrimBlocks:opts.IstrimBlocks || true,
        trimBlocks:opts.trimBlocks || true
    }

    let env = nunjucks.configure('view',nunjucksConfig);
    return env;
}

let MiddleWare = async(ctx,next)=>{
    let env = createEnv();
    ctx.render=(view,model)=>{
        ctx.body = env.render(view,model);
    }
    await next();
}

module.exports=MiddleWare;
